#include "level3.h"

Level3::Level3(QWidget *parent)
    : LevelScene(QPixmap(RESOURCE_DIR + "/Rose_Future_Map.png"),QImage(RESOURCE_DIR + "/Rose_Future_Mask.png"), parent)
{
    buildingImage = new GameBackground(QPixmap(RESOURCE_DIR + "/Rose_Future_Buildings.png"),mainScene);
    buildingImage->setZValue(1);

    river = new River(QPixmap(RESOURCE_DIR + "/1water1.png"),mainScene,this);
    QObject::connect(river,SIGNAL(clicked()),this,SLOT(riverClicked()));
    QObject::connect(river,SIGNAL(hoverChanged(bool)),this,SLOT(riverHoverChanged(bool)));

    // Add the tools
    quarantineTool = addTool(15,QString("Quarantien (Place road block)"),RESOURCE_DIR + "/buttons/Dean_RoadBlock.png");
    sterilizationTool = addTool(5,QString("Sterilize building"),RESOURCE_DIR + "/buttons/Dean_Sterilize.png");
    cleanWaterTool = addTool(300,QString("Clean city water supply"),RESOURCE_DIR + "/buttons/Dean_CleanWater.png");
    coughSyrupTool = addTool(5,QString("Give people in a building cough syrup"),RESOURCE_DIR + "/buttons/Dean_CoughSyrup.png");
    antiViralsTool = addTool(10,QString("Give building Antivirals"),RESOURCE_DIR + "/buttons/Dean_AntiVir.png");
    gammaGlobulinTool = addTool(10,QString("Treat building with Gamma Globulins"),RESOURCE_DIR + "/buttons/Dean_GammaGlobulians.png");
    vacceneTool = addTool(30,QString("Vaccinate Building"),RESOURCE_DIR + "/buttons/Dean_Vaccine.png");
    interferonTool = addTool(10,QString("Treat building with Interferons"),RESOURCE_DIR + "/buttons/Dean_Interferon.png");
    geneTherapyTool = addTool(45,QString("Give people in a building gene therapy"),RESOURCE_DIR + "/buttons/Dean_GeneTherapy.png");
    nanoBotTherapyTool = addTool(45,QString("Give people in a building NanoBot therapy"),RESOURCE_DIR + "/buttons/Dean_NanoBot.png");

    // Add one story houses
    QPointF house1Info[44][2] = {{QPointF(220,895),QPointF(23,91)},
                                 {QPointF(220+52,895),QPointF(31,91)},
                                 {QPointF(220,946),QPointF(24,98)},
                                 {QPointF(220+52,946),QPointF(29,98)},

                                 {QPointF(344,895),QPointF(35,91)},
                                 {QPointF(344+52,895),QPointF(43,91)},
                                 {QPointF(344,946),QPointF(37,98)},
                                 {QPointF(344+52,946),QPointF(42,98)},

                                 {QPointF(14,1020),QPointF(5,104)},
                                 {QPointF(14,1020+51),QPointF(4,111)},

                                 {QPointF(96,1020),QPointF(10,104)},
                                 {QPointF(96+52,1020),QPointF(18,104)},
                                 {QPointF(96,1020+51),QPointF(12,111)},
                                 {QPointF(96+52,1020+51),QPointF(17,111)},

                                 {QPointF(220,1020),QPointF(23,104)},
                                 {QPointF(220+52,1020),QPointF(31,104)},
                                 {QPointF(220,1020+51),QPointF(25,111)},
                                 {QPointF(220+52,1020+51),QPointF(30,111)},

                                 {QPointF(344,1020),QPointF(35,104)},
                                 {QPointF(344+52,1020),QPointF(43,104)},
                                 {QPointF(344,1020+51),QPointF(37,111)},
                                 {QPointF(344+52,1020+51),QPointF(42,111)},

                                 {QPointF(14,1144),QPointF(5,116)},
                                 {QPointF(14,1144+51),QPointF(4,123)},

                                 {QPointF(96,1144),QPointF(10,116)},
                                 {QPointF(96+52,1144),QPointF(18,116)},
                                 {QPointF(96,1144+51),QPointF(12,123)},
                                 {QPointF(96+52,1144+51),QPointF(17,123)},

                                 {QPointF(220,1144),QPointF(23,116)},
                                 {QPointF(220+52,1144),QPointF(31,116)},
                                 {QPointF(220,1144+51),QPointF(25,123)},
                                 {QPointF(220+52,1144+51),QPointF(30,123)},

                                 {QPointF(1922,346),QPointF(193,37)},
                                 {QPointF(1922,346+51),QPointF(194,43)},
                                 {QPointF(1922,478),QPointF(193,50)},
                                 {QPointF(1922,478+60),QPointF(194,58)},
                                 {QPointF(1922,628),QPointF(193,65)},
                                 {QPointF(1922,628+60),QPointF(194,73)},
                                 {QPointF(1922,778),QPointF(193,80)},
                                 {QPointF(1922,778+60),QPointF(195,88)},
                                 {QPointF(1922,928),QPointF(193,95)},
                                 {QPointF(1922,928+60),QPointF(195,103)},
                                 {QPointF(1922,1078),QPointF(193,110)},
                                 {QPointF(1922,1078+60),QPointF(194,118)},
                               };

    for (unsigned int index = 0; index < (sizeof(house1Info)/(sizeof(*house1Info[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 4);
        addBuilding(QPoint(house1Info[index][1].toPoint()),QPointF(house1Info[index][0]),QPixmap(RESOURCE_DIR + "/buildings/Rose_1home" + buildingColor + ".png"));
    }

    // Add two story houses
    QPointF house2Info[45][2] = {{QPointF(1076,245),QPointF(110,31)},
                                 {QPointF(1076+65,245),QPointF(116,31)},
                                 {QPointF(1373,371),QPointF(139,43)},
                                 {QPointF(1373+50,371),QPointF(144,43)},
                                 {QPointF(1498,371),QPointF(152,43)},
                                 {QPointF(1498+50,371),QPointF(157,43)},
                                 {QPointF(1749,371),QPointF(177,43)},
                                 {QPointF(1749+55,371),QPointF(182,43)},
                                 {QPointF(1749,520),QPointF(177,58)},
                                 {QPointF(1749+55,520),QPointF(182,58)},
                                 {QPointF(1623,520),QPointF(165,58)},
                                 {QPointF(1623+50,520),QPointF(170,58)},
                                 {QPointF(1749,822),QPointF(177,88)},
                                 {QPointF(1749+55,822),QPointF(183,88)},
                                 {QPointF(1749,972),QPointF(177,103)},
                                 {QPointF(1749+55,972),QPointF(183,103)},
                                 {QPointF(1749,1122),QPointF(177,118)},
                                 {QPointF(1749+55,1122),QPointF(183,118)},
                                 {QPointF(1621,1122),QPointF(164,118)},
                                 {QPointF(1621+51,1122),QPointF(170,118)},
                                 {QPointF(1496,1122),QPointF(152,118)},
                                 {QPointF(1496+51,1122),QPointF(157,118)},

                                 {QPointF(47,70),QPointF(7,13)},
                                 {QPointF(47+50,70),QPointF(12,13)},
                                 {QPointF(172,70),QPointF(20,13)},
                                 {QPointF(172+50,70),QPointF(24,13)},
                                 {QPointF(297,196),QPointF(32,25)},
                                 {QPointF(297+50,196),QPointF(37,25)},
                                 {QPointF(297,322),QPointF(32,38)},
                                 {QPointF(297+50,322),QPointF(37,38)},
                                 {QPointF(172,322),QPointF(19,38)},
                                 {QPointF(172+50,322),QPointF(24,38)},
                                 {QPointF(89,322),QPointF(11,38)},

                                 {QPointF(1172,45),QPointF(119,10)},
                                 {QPointF(1172+50,45),QPointF(124,10)},
                                 {QPointF(1297,45),QPointF(132,10)},
                                 {QPointF(1297+50,45),QPointF(137,10)},
                                 {QPointF(1422,45),QPointF(144,10)},
                                 {QPointF(1422+50,45),QPointF(149,10)},
                                 {QPointF(1547,45),QPointF(157,10)},
                                 {QPointF(1547+50,45),QPointF(162,10)},
                                 {QPointF(1672,45),QPointF(169,10)},
                                 {QPointF(1672+50,45),QPointF(174,10)},

                                 {QPointF(10,694),QPointF(3,74)},
                                 {QPointF(2,798),QPointF(2,86)},
                                };

    for (unsigned int index = 0; index < (sizeof(house2Info)/(sizeof(*house2Info[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 4);
        addBuilding(QPoint(house2Info[index][1].toPoint()),QPointF(house2Info[index][0]),QPixmap(RESOURCE_DIR + "/buildings/Rose_2home" + buildingColor + ".png"));
    }

    // Add three story house
    QPointF house3Info[6][2] = {{QPointF(1224,223),QPointF(129,29)},
                                {QPointF(299,49),QPointF(37,11)},
                                {QPointF(424,174),QPointF(49,24)},
                                {QPointF(424,299),QPointF(49,36)},
                                {QPointF(1049,0),QPointF(112,6)},
                                {QPointF(924,-25),QPointF(99,4)},
                                };

    for (unsigned int index = 0; index < (sizeof(house3Info)/(sizeof(*house3Info[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 4);
        addBuilding(QPoint(house3Info[index][1].toPoint()),QPointF(house3Info[index][0]),QPixmap(RESOURCE_DIR + "/buildings/Rose_3home" + buildingColor + "-small.png"));
    }

    // Add office buildings
    QPointF officeInfo[33][2] = {{QPointF(767,325),QPointF(80,43)},
                                 {QPointF(767+65,325),QPointF(87,43)},
                                 {QPointF(917,325),QPointF(95,43)},
                                 {QPointF(917+65,325),QPointF(102,43)},
                                 {QPointF(1066,325),QPointF(110,43)},
                                 {QPointF(1066+65,325),QPointF(117,43)},
                                 {QPointF(1217,325),QPointF(125,43)},
                                 {QPointF(1217+65,325),QPointF(132,43)},

                                 {QPointF(767,470),QPointF(80,58)},
                                 {QPointF(767+65,470),QPointF(86,58)},
                                 {QPointF(917,470),QPointF(95,58)},
                                 {QPointF(917+65,470),QPointF(101,58)},
                                 {QPointF(767,620),QPointF(80,73)},
                                 {QPointF(767+65,620),QPointF(86,73)},
                                 {QPointF(917,620),QPointF(95,73)},
                                 {QPointF(917+65,620),QPointF(101,73)},
                                 {QPointF(917,770),QPointF(95,88)},
                                 {QPointF(917+65,770),QPointF(101,88)},
                                 {QPointF(1066,470),QPointF(110,58)},
                                 {QPointF(1066+65,470),QPointF(116,58)},
                                 {QPointF(1217,470),QPointF(125,58)},
                                 {QPointF(1217+65,470),QPointF(131,58)},
                                 {QPointF(1380,470),QPointF(141,58)},
                                 {QPointF(1402,620),QPointF(143,73)},
                                 {QPointF(1367,770),QPointF(140,88)},
                                 {QPointF(1380,920),QPointF(141,103)},
                                 {QPointF(1380,1070),QPointF(141,118)},
                                 {QPointF(1216,1070),QPointF(125,118)},
                                 {QPointF(1216+65,1070),QPointF(131,118)},
                                 {QPointF(767,920),QPointF(80,103)},
                                 {QPointF(767+65,920),QPointF(87,103)},
                                 {QPointF(767,1070),QPointF(80,118)},
                                 {QPointF(767+65,1070),QPointF(87,118)},
                                };

    for (unsigned int index = 0; index < (sizeof(officeInfo)/(sizeof(*officeInfo[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 3);
        addBuilding(QPoint(officeInfo[index][1].toPoint()),QPointF(officeInfo[index][0]),QPixmap(RESOURCE_DIR + "/buildings/1Skyscraper" + buildingColor + ".png"));
    }

    // Add stores
    QPointF storesInfo[14][2] = {{QPointF(766,223),QPointF(79,24)},
                                 {QPointF(766,272),QPointF(79,30)},
                                 {QPointF(834,223),QPointF(87,24)},
                                 {QPointF(834,272),QPointF(86,30)},

                                 {QPointF(916,223),QPointF(94,24)},
                                 {QPointF(916,272),QPointF(94,30)},
                                 {QPointF(984,223),QPointF(102,24)},
                                 {QPointF(984,272),QPointF(101,30)},

                                 {QPointF(1638,633),QPointF(166,66)},
                                 {QPointF(1638,695),QPointF(166,72)},

                                 {QPointF(1514,783),QPointF(154,80)},
                                 {QPointF(1514,844),QPointF(154,87)},

                                 {QPointF(1624,778),QPointF(165,80)},
                                 {QPointF(1650,844),QPointF(167,87)},
                                };

    for (unsigned int index = 0; index < (sizeof(storesInfo)/(sizeof(*storesInfo[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 3);
        addBuilding(QPoint(storesInfo[index][1].toPoint()),QPointF(storesInfo[index][0]),QPixmap(RESOURCE_DIR + "/buildings/2Store" + buildingColor + ".png"));
    }

    // Add factories
    QPointF factoriesInfo[7][2] = {{QPointF(174,423),QPointF(22,50)},
                                    {QPointF(299,423),QPointF(34,24)},
                                    {QPointF(424,423),QPointF(47,24)},
                                    {QPointF(299,548),QPointF(34,62)},
                                    {QPointF(424,548),QPointF(47,62)},
                                    {QPointF(299,627),QPointF(34,70)},
                                    {QPointF(424,674),QPointF(47,75)},
                                   };

    for (unsigned int index = 0; index < (sizeof(factoriesInfo)/(sizeof(*factoriesInfo[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 5);
        addBuilding(QPoint(factoriesInfo[index][1].toPoint()),QPointF(factoriesInfo[index][0]),QPixmap(RESOURCE_DIR + "/buildings/2Factory" + buildingColor + ".png"));
    }

    // Add other buildings
    addBuilding(QPoint(88,85),QPointF(775,785),QPixmap(RESOURCE_DIR + "/buildings/2PostOffice.png"));
    addBuilding(QPoint(93,102),QPointF(920,935),QPixmap(RESOURCE_DIR + "/buildings/1FireStation.png"));
    addBuilding(QPoint(113,72),QPointF(1071,618),QPixmap(RESOURCE_DIR + "/buildings/2CityHall1.png"));
    addBuilding(QPoint(113,87),QPointF(1069,766),QPixmap(RESOURCE_DIR + "/buildings/2CourtHouse1.png"));
    addBuilding(QPoint(112,103),QPointF(1069,917),QPixmap(RESOURCE_DIR + "/buildings/2policestation1.png"));
    addBuilding(QPoint(128,64),QPointF(1219,616.5),QPixmap(RESOURCE_DIR + "/buildings/2school1.png"));
    addBuilding(QPoint(157,99),QPointF(1498,925),QPixmap(RESOURCE_DIR + "/buildings/1school2.png"));
    addBuilding(QPoint(165,99),QPointF(1622,925),QPixmap(RESOURCE_DIR + "/buildings/1school1-small.png"));
    addBuilding(QPoint(17,96),QPointF(98,897),QPixmap(RESOURCE_DIR + "/buildings/1school2.png"));
    addBuilding(QPoint(181,72),QPointF(1743,620),QPixmap(RESOURCE_DIR + "/buildings/1hospital1.png"));
    addBuilding(QPoint(21,24),QPointF(41,159),QPixmap(RESOURCE_DIR + "/buildings/2hospital1.png"));
    addBuilding(QPoint(37,120),QPointF(348,1148),QPixmap(RESOURCE_DIR + "/buildings/3policestation1.png"));
    addBuilding(QPoint(42,120),QPointF(395,1156),QPixmap(RESOURCE_DIR + "/buildings/2FireStation.png"));
    addBuilding(QPoint(167,41),QPointF(1624,356),QPixmap(RESOURCE_DIR + "/buildings/3Bank1.png"));          //
    addBuilding(QPoint(154,55),QPointF(1499,482),QPixmap(RESOURCE_DIR + "/buildings/1Mall1-small.png"));
    addBuilding(QPoint(154,71),QPointF(1499,632),QPixmap(RESOURCE_DIR + "/buildings/1Mall1-small.png"));
    addBuilding(QPoint(128,84),QPointF(1223,780),QPixmap(RESOURCE_DIR + "/buildings/1library1.png"));
    addBuilding(QPoint(128,102),QPointF(1226,923),QPixmap(RESOURCE_DIR + "/buildings/2Bank1.png"));
    addBuilding(QPoint(113,116),QPointF(921,1070),QPixmap(RESOURCE_DIR + "/buildings/2Mall1.png"));
    addBuilding(QPoint(25,61),QPointF(176,548),QPixmap(RESOURCE_DIR + "/buildings/1Factory1.png"));


    QString convertString;

    for (int count = 0; count<1000; count ++)
    {
        convertString.setNum((rand()%12) + 1);
        addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(rand() % buildings.length()));
    }

    for (int count = 0; count<30; count ++)
    {
        convertString.setNum((rand()%12) + 1);
        int r = rand() % 3;
        if (r == 0)
            addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(118));
        else if (r == 1)
            addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(119));
        else
            addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(154));
        people.last()->virus = new Virus(800,225,250,0,people.last());
    }

    healthyCountThreshold = people.length() - 125;
    healthyTimeThreshold = QTime(0,2,0,0);

    maxPeopleOnStreet = 50;
    currentLevel = levelScene3;
}
